home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 22 / Cream of the Crop 22.iso / program / eflibpt4.zip / DEMO / DATATYPE / LINKWALK.PAS < prev    next >
Pascal/Delphi Source File  |  1996-08-18  |  2KB  |  59 lines

  1. { Borland Pascal Extended Function Library - EFLIB (C) Johan Larsson, 1996
  2.   Demonstration; linked list node walking
  3.  
  4.   EFLIB IS PROTECTED BY THE COPYRIGHT LAW AND MAY NOT BE COPIED, SOLD OR
  5.   MANIPULATED. FOR MORE INFORMATION, SEE PROGRAM MANUAL! THIS DEMONSTRAT-
  6.   ION PROGRAM MAY FREELY BE USED AND DISTRIBUTED.                          }
  7.  
  8.  
  9. uses EFLIBDEF, EFLIBINI, EFLIBBAS, EFLIBDAT, CRT;
  10.  
  11. var MyList : TextObjectType;
  12.     MyNode : LinkageObjectPointerType;
  13.  
  14.  
  15. { Far procedure to pass as a parameter to the ForEach method }
  16. procedure View (var Data : string; var Continue : boolean); far;
  17. begin
  18.      Write (Data, ' ');
  19. end;
  20.  
  21.  
  22. begin
  23.      with MyList do begin
  24.           { Initialize a structure based on text strings }
  25.           Initialize;
  26.  
  27.           { Add some nodes to the structure }
  28.           AddText ('With'); AddText ('node'); AddText ('walking'); AddText ('it''s');
  29.           AddText ('very'); AddText ('easy'); AddText ('to'); AddText ('access');
  30.           AddText ('the'); AddText ('node'); AddText ('you'); AddText ('want');
  31.           AddText ('to'); AddText ('access.');
  32.  
  33.           { Walk to the last node using the the node two nodes before the last
  34.             node as starting node for the walk. }
  35.           MyNode := LastNode^.Predecessor^.Predecessor;
  36.           Walk (MyNode, 2);
  37.           WriteLn ('We have now walked two nodes to the last node (', NodeIndex(MyNode), ').');
  38.  
  39.           { Walk forward two nodes }
  40.           Walk (MyNode, -2);
  41.           WriteLn ('Back there we started walking (', NodeIndex(MyNode), ').');
  42.  
  43.           { Walk to the node two nodes after the first node (relatively). }
  44.           WalkUsing (MyNode, FirstNode, 2);
  45.           WriteLn ('Walked two steps forward from first node (', NodeIndex(MyNode), ').');
  46.  
  47.           { Walk to the node two nodes after the first node (relatively). }
  48.           WalkUsing (MyNode, MyNode, -2);
  49.           WriteLn ('Walked back again (', NodeIndex(MyNode), ').');
  50.  
  51.           { Display the nodes }
  52.           WriteLn; ForEach (@View); WriteLn;
  53.  
  54.           { Dispose structure (intercept object }
  55.           Intercept;
  56.      end;
  57.  
  58.      if GlobalDataError then WriteLn ('Error(s) reported!');
  59. end.